<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>08-解决问题 | hez2010</title>
  
  
  
  <!--link rel="stylesheet" href="//cdn.jsdelivr.net/highlight.js/9.10.0/styles/github-gist.min.css"-->
  
<link rel="stylesheet" href="//cdn.jsdelivr.net/highlight.js/9.10.0/styles/github-gist.min.css">

  
<link rel="stylesheet" href="/css/style.css">

<!-- hexo injector head_end start -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.css">

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hexo-math@4.0.0/dist/style.css">
<!-- hexo injector head_end end --><meta name="generator" content="Hexo 5.1.1"></head>

<body>
<div class="Shell">
    <aside class='SideBar'>
    <section class='avatar' style="background-image: url()">
        <div class='av-pic' style="background-image: url(/assets/avatar.jpg)">
        </div>
    </section>
    <section class='menu'>
        <div>hez2010</div>
        
            <div>软件工程导论</div>
        
        <ul>
          
            <a href="/" class="Btn">
              <li>Home</li>
            </a>  
          
            <a href="/archives/" class="Btn">
              <li>Archive</li>
            </a>  
          
        </ul>
    </section>
    <section class="media">
        
            
                <a target="_blank" rel="noopener" href="https://github.com/hez2010">
                    <img src="/assets/github.svg" />
                </a>
            
        
    </section>
</aside>

    <div class="container">
        <div data-pager-shell>
            <div>
  <article class='ContentView'>
    <header class='PageTitle'>
        <h1>08-解决问题</h1>
    </header>

    <section>
      <h1 id="Homework"><a href="#Homework" class="headerlink" title="Homework"></a>Homework</h1><h2 id="阅读-Pseudocode-Standard"><a href="#阅读-Pseudocode-Standard" class="headerlink" title="阅读 Pseudocode Standard"></a>阅读 Pseudocode Standard</h2><h3 id="用伪代码描述将十进制转换成16进制的方法"><a href="#用伪代码描述将十进制转换成16进制的方法" class="headerlink" title="用伪代码描述将十进制转换成16进制的方法"></a>用伪代码描述将十进制转换成16进制的方法</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><code class="hljs pdl">READ input<br>SET result to &quot;&quot;<br>SET isneg to false<br>IF input &lt; 0 THEN<br>    SET isneg to true<br>    SET input to -input<br>ENDIF<br><br>WHILE input &gt; 0<br>    SET a to input % 16<br>    SET input to input &#x2F; 16<br>    SET bit to a + &#39;0&#39;<br>    IF a &gt; 9 THEN<br>        SET bit to bit - &#39;9&#39; - 1 + &#39;A&#39;<br>    ENDIF<br>    INSERT bit to result at position 0<br>ENDWHILE<br><br>IF result &#x3D;&#x3D; &quot;&quot;<br>    SET result to &quot;0&quot;<br>ENDIF<br><br>IF igneg THEN<br>    INSERT &#39;-&#39; to result at position 0<br>ENDIF<br><br>PRINT result<br></code></pre></td></tr></table></figure>
<a id="more"></a>
<h3 id="C语言实现（先用注释写好算法，然后翻译）"><a href="#C语言实现（先用注释写好算法，然后翻译）" class="headerlink" title="C语言实现（先用注释写好算法，然后翻译）"></a>C语言实现（先用注释写好算法，然后翻译）</h3><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br></pre></td><td class="code"><pre><code class="hljs c"><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;stdio.h&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;string.h&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;stdbool.h&gt;</span></span><br><br><span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">insert_char</span><span class="hljs-params">(<span class="hljs-keyword">char</span>* str, <span class="hljs-keyword">char</span> ch)</span> </span>&#123;<br>    <span class="hljs-keyword">int</span> len = <span class="hljs-built_in">strlen</span>(str);<br>    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = len - <span class="hljs-number">1</span>; i &gt;= <span class="hljs-number">0</span>; i--) &#123;<br>        str[i + <span class="hljs-number">1</span>] = str[i];<br>    &#125;<br>    str[len + <span class="hljs-number">1</span>] = <span class="hljs-number">0</span>;<br>    str[<span class="hljs-number">0</span>] = ch;<br>&#125;<br><br><span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">()</span> </span>&#123;<br>    <span class="hljs-comment">// READ input</span><br>    <span class="hljs-keyword">int</span> input;<br>    <span class="hljs-built_in">scanf</span>(<span class="hljs-string">&quot;%d&quot;</span>, &amp;input);<br>    <span class="hljs-comment">// SET result to &quot;&quot;</span><br>    <span class="hljs-keyword">char</span> result[<span class="hljs-number">1000</span>];<br>    <span class="hljs-built_in">memset</span>(result, <span class="hljs-number">0</span>, <span class="hljs-keyword">sizeof</span>(result)); <br>    <span class="hljs-comment">// SET isneg to false</span><br>    <span class="hljs-keyword">bool</span> isneg = <span class="hljs-literal">false</span>;<br><br>    <span class="hljs-comment">// IF input &lt; 0 THEN</span><br>    <span class="hljs-keyword">if</span> (input &lt; <span class="hljs-number">0</span>) &#123;<br>        <span class="hljs-comment">// SET isneg to true</span><br>        isneg = <span class="hljs-literal">true</span>;<br>        <span class="hljs-comment">// SET input to -input</span><br>        input = -input;<br>    <span class="hljs-comment">// ENDIF</span><br>    &#125;<br><br>    <span class="hljs-comment">// WHILE input &gt; 0</span><br>    <span class="hljs-keyword">while</span> (input &gt; <span class="hljs-number">0</span>) &#123;<br>        <span class="hljs-comment">// SET a to input % 16</span><br>        <span class="hljs-keyword">int</span> a = input % <span class="hljs-number">16</span>;<br>        <span class="hljs-comment">// SET input to input / 16</span><br>        input = input / <span class="hljs-number">16</span>;<br>        <span class="hljs-comment">// SET bit to a + &#x27;0&#x27;</span><br>        <span class="hljs-keyword">char</span> bit = a + <span class="hljs-string">&#x27;0&#x27;</span>;<br>        <span class="hljs-comment">// IF a &gt; 9 THEN</span><br>        <span class="hljs-keyword">if</span> (a &gt; <span class="hljs-number">9</span>) &#123;<br>            <span class="hljs-comment">// SET bit to bit - &#x27;9&#x27; - 1 + &#x27;A&#x27;</span><br>            bit = bit - <span class="hljs-string">&#x27;9&#x27;</span> - <span class="hljs-number">1</span> + <span class="hljs-string">&#x27;A&#x27;</span>;<br>        <span class="hljs-comment">// ENDIF</span><br>        &#125;<br>        <span class="hljs-comment">// INSERT bit to result at position 0</span><br>        insert_char(result, bit);<br>    <span class="hljs-comment">// ENDWHILE</span><br>    &#125;<br><br>    <span class="hljs-comment">// IF result == &quot;&quot;</span><br>    <span class="hljs-keyword">if</span> (result[<span class="hljs-number">0</span>] == <span class="hljs-number">0</span>) &#123;<br>        <span class="hljs-comment">// SET result to &quot;0&quot;</span><br>        result[<span class="hljs-number">0</span>] = <span class="hljs-string">&#x27;0&#x27;</span>;<br>        result[<span class="hljs-number">1</span>] = <span class="hljs-number">0</span>;<br>    <span class="hljs-comment">// ENDIF</span><br>    &#125;<br><br>    <span class="hljs-comment">// IF igneg THEN</span><br>    <span class="hljs-keyword">if</span> (isneg) &#123;<br>        <span class="hljs-comment">// INSERT &#x27;-&#x27; to result at position 0</span><br>        insert_char(result, <span class="hljs-string">&#x27;-&#x27;</span>);<br>    <span class="hljs-comment">// ENDIF</span><br>    &#125;<br><br>    <span class="hljs-comment">// PRINT result</span><br>    <span class="hljs-built_in">printf</span>(<span class="hljs-string">&quot;%s\n&quot;</span>, result);<br>    <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;<br>&#125;<br></code></pre></td></tr></table></figure>

<h3 id="使用-1-0-1-15-26，3265-最为输入测试你的程序"><a href="#使用-1-0-1-15-26，3265-最为输入测试你的程序" class="headerlink" title="使用 -1, 0, 1, 15, 26，3265 最为输入测试你的程序"></a>使用 -1, 0, 1, 15, 26，3265 最为输入测试你的程序</h3><p><img src="/assets/8/1.png" alt="1.png"></p>
<p>与计算器计算出的结果一致。</p>
<h2 id="名词解释与对比"><a href="#名词解释与对比" class="headerlink" title="名词解释与对比"></a>名词解释与对比</h2><h3 id="Top-down-design"><a href="#Top-down-design" class="headerlink" title="Top-down design"></a>Top-down design</h3><p>自顶向下设计。</p>
<p>这是一种逐步求精的设计程序的过程和方法。对要完成的任务进行分解，先对最高层次中的问题进行定义、设计、编程和测试，而将其中未解决的问题作为一个子任务放到下一层次中去解决。这样逐层、逐个地进行定义、设计、编程和测试，直到所有层次上的问题均由实用程序来解决，就能设计出具有层次结构的程序。</p>
<p>按自顶向下的方法设计时，设计师首先对所设计的系统要有一个全面的理解。然后从顶层开始，连续地逐层向下分解，起到系统的所有模块都小到便于掌握为止。</p>
<h3 id="Work-breakdown-structure-WBS"><a href="#Work-breakdown-structure-WBS" class="headerlink" title="Work breakdown structure (WBS)"></a>Work breakdown structure (WBS)</h3><p>工作分解结构。</p>
<p>把一个项目按一定的原则分解，项目分解成任务，任务再分解成一项项工作，再把一项项工作分配到每个人的日常活动中，直到分解不下去为止。</p>
<h3 id="简述管理学WBS-与信息学Top-down设计的异同"><a href="#简述管理学WBS-与信息学Top-down设计的异同" class="headerlink" title="简述管理学WBS 与信息学Top-down设计的异同"></a>简述管理学WBS 与信息学Top-down设计的异同</h3><p>相同之处：都是将大问题划分为子问题，使得解决问题更加容易。</p>
<p>不同之处：WBS和Top-down属于两个不容的领域，一个是管理学，一个是计算机科学。另外，Top-down是从上到下进行分解，并且需要对分解出的每个子问题进行测试；而WBS则是根据工作类型和范围进行分解，需要对每个子工作的结果进行管控。</p>
<h2 id="仔细观察您洗衣机的运作过程，运用Top-down设计方法和Pseudocode-描述洗衣机控制程序"><a href="#仔细观察您洗衣机的运作过程，运用Top-down设计方法和Pseudocode-描述洗衣机控制程序" class="headerlink" title="仔细观察您洗衣机的运作过程，运用Top-down设计方法和Pseudocode 描述洗衣机控制程序"></a>仔细观察您洗衣机的运作过程，运用Top-down设计方法和Pseudocode 描述洗衣机控制程序</h2><p>假设洗衣机可执行的基本操作如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs none">water_in_switch(open_close) &#x2F;&#x2F; open 打开上水开关，close关闭 <br>water_out_switch(open_close) &#x2F;&#x2F; open 打开排水开关，close关闭<br>get_water_volume() &#x2F;&#x2F;返回洗衣机内部水的高度<br>motor_run(direction) &#x2F;&#x2F; 电机转动。left左转，right右转，stop停 <br>time_counter() &#x2F;&#x2F; 返回当前时间计数，以秒为单位<br>halt(returncode) &#x2F;&#x2F;停机，success 成功 failure 失败<br></code></pre></td></tr></table></figure>

<h3 id="请使用伪代码分解“正常洗衣”程序的大步骤。包括注水、浸泡等"><a href="#请使用伪代码分解“正常洗衣”程序的大步骤。包括注水、浸泡等" class="headerlink" title="请使用伪代码分解“正常洗衣”程序的大步骤。包括注水、浸泡等"></a>请使用伪代码分解“正常洗衣”程序的大步骤。包括注水、浸泡等</h3><ul>
<li>注水</li>
<li>浸泡</li>
<li>洗涤</li>
<li>排水</li>
<li>干燥</li>
<li>关机</li>
</ul>
<h3 id="进一步用基本操作、控制语句（IF、FOR、WHILE等）、变量与表达式，写出每个步骤的伪代码"><a href="#进一步用基本操作、控制语句（IF、FOR、WHILE等）、变量与表达式，写出每个步骤的伪代码" class="headerlink" title="进一步用基本操作、控制语句（IF、FOR、WHILE等）、变量与表达式，写出每个步骤的伪代码"></a>进一步用基本操作、控制语句（IF、FOR、WHILE等）、变量与表达式，写出每个步骤的伪代码</h3><h4 id="注水"><a href="#注水" class="headerlink" title="注水"></a>注水</h4><p>假设用户设置的水量为 <code>volumn_set</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs pdl">CALL motor_run with stop<br>CALL water_out_switch with close<br>CALL water_in_switch with open<br>REPECT<br>    CALL get_water_volume RETURNING volume<br>UNTIL volumn &gt;&#x3D; volumn_set<br>CALL water_in_switch with close<br></code></pre></td></tr></table></figure>

<h4 id="浸泡"><a href="#浸泡" class="headerlink" title="浸泡"></a>浸泡</h4><p>假设用户设置的浸泡时间为 <code>soaking_time</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs pdl">CALL motor_run with stop<br>CALL water_out_switch with close<br>CALL water_in_switch with close<br>REPECT<br>    CALL time_counter RETURNING time<br>UNTIL time &gt;&#x3D; soaking_time<br></code></pre></td></tr></table></figure>

<h4 id="洗涤"><a href="#洗涤" class="headerlink" title="洗涤"></a>洗涤</h4><p>假设用户设置的洗涤时间为 <code>washing_time</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs pdl">CALL water_out_switch with close<br>CALL water_in_switch with close<br>REPECT<br>    CALL motor_run with right<br>    CALL motor_run with left<br>    CALL time_counter RETURNING time<br>UNTIL time &gt;&#x3D; washing_time<br>CALL motor_run with stop<br></code></pre></td></tr></table></figure>

<h4 id="排水"><a href="#排水" class="headerlink" title="排水"></a>排水</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs pdl">CALL water_out_switch with open<br>CALL water_in_switch with close<br>CALL motor_run with stop<br>REPECT<br>    CALL get_water_volume RETURNING volume<br>UNTIL volume &#x3D;&#x3D; 0<br></code></pre></td></tr></table></figure>

<h4 id="干燥"><a href="#干燥" class="headerlink" title="干燥"></a>干燥</h4><p>假设用户设置的干燥时间为 <code>dry_time</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs pdl">CALL water_out_switch with open<br>CALL water_in_switch with close<br>CALL motor_run with right<br>REPECT<br>    CALL time_counter RETURNING time<br>UNTIL time &gt;&#x3D; dry_time<br>CALL motor_run with stop<br></code></pre></td></tr></table></figure>

<h4 id="关机"><a href="#关机" class="headerlink" title="关机"></a>关机</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs pdl">CALL water_out_switch with close<br>CALL water_in_switch with close<br>CALL motor_run with stop<br>CALL halt with success<br></code></pre></td></tr></table></figure>

<h3 id="根据你的实践，请分析“正常洗衣”与“快速洗衣”在用户目标和程序上的异同。你认为是否存在改进（创新）空间，简单说明你的改进意见？"><a href="#根据你的实践，请分析“正常洗衣”与“快速洗衣”在用户目标和程序上的异同。你认为是否存在改进（创新）空间，简单说明你的改进意见？" class="headerlink" title="根据你的实践，请分析“正常洗衣”与“快速洗衣”在用户目标和程序上的异同。你认为是否存在改进（创新）空间，简单说明你的改进意见？"></a>根据你的实践，请分析“正常洗衣”与“快速洗衣”在用户目标和程序上的异同。你认为是否存在改进（创新）空间，简单说明你的改进意见？</h3><ul>
<li>正常洗衣针对一般情况，对已经比较脏的衣服进行清洗，因此步骤相对较多，每个步骤的时间也较长。</li>
<li>快速洗衣针对时间预算较少的情况，使得较短时间内能够完成基本的洗衣任务，步骤相对较少，且每个步骤的时间也相应缩短。</li>
</ul>
<h4 id="改进意见"><a href="#改进意见" class="headerlink" title="改进意见"></a>改进意见</h4><p>可以将正常洗衣和快速洗衣作为模板，允许用户自定义选择步骤和输入每个步骤的时间，将洗衣过程模块化、自定义化。</p>
<h3 id="通过步骤3），提取一些共性功能模块（函数），简化“正常洗衣”程序，使程序变得更利于人类理解和修改维护。"><a href="#通过步骤3），提取一些共性功能模块（函数），简化“正常洗衣”程序，使程序变得更利于人类理解和修改维护。" class="headerlink" title="通过步骤3），提取一些共性功能模块（函数），简化“正常洗衣”程序，使程序变得更利于人类理解和修改维护。"></a>通过步骤3），提取一些共性功能模块（函数），简化“正常洗衣”程序，使程序变得更利于人类理解和修改维护。</h3><p>例如：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs none">wait(time) &#x2F;&#x2F;等待指定的时间<br>注水(volume,timeout) &#x2F;&#x2F;在指定时间内完成注水，否则停机；<br>排水(timeout)<br></code></pre></td></tr></table></figure>
<p>等子程序</p>
<h4 id="wait-time"><a href="#wait-time" class="headerlink" title="wait(time)"></a>wait(time)</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs pdl">REPEAT<br>    CALL time_counter RETURNING current_time<br>UNTIL current_time &gt;&#x3D; time<br></code></pre></td></tr></table></figure>

<h3 id="注水-volume-timeout"><a href="#注水-volume-timeout" class="headerlink" title="注水(volume, timeout)"></a>注水(volume, timeout)</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs pdl">CALL motor_run with stop<br>CALL water_out_switch with close<br>CALL water_in_switch with open<br>REPECT<br>    CALL time_counter RETURNING current_time<br>    CALL get_water_volume RETURNING current_volume<br>    IF current_time &gt;&#x3D; timeout THEN<br>        CALL water_in_switch with close<br>        CALL halt with failure<br>        BREAK<br>    ENDIF<br>UNTIL current_volumn &gt;&#x3D; volume<br>CALL water_in_switch with close<br></code></pre></td></tr></table></figure>

<h3 id="排水-timeout"><a href="#排水-timeout" class="headerlink" title="排水(timeout)"></a>排水(timeout)</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs pdl">CALL water_out_switch with open<br>CALL water_in_switch with close<br>CALL motor_run with stop<br>REPECT<br>    CALL time_counter RETURNING current_time<br>    CALL get_water_volume RETURNING volume<br>    IF current_time &gt;&#x3D; timeout THEN<br>        CALL halt with failure<br>        BREAK<br>    ENDIF<br>UNTIL volume &#x3D;&#x3D; 0<br></code></pre></td></tr></table></figure>

<h2 id="根据后面的素材，识别类和对象"><a href="#根据后面的素材，识别类和对象" class="headerlink" title="根据后面的素材，识别类和对象"></a>根据后面的素材，识别类和对象</h2><h3 id="阅读“牧师与恶魔过河”（-http-www-17yy-com-f-69854-html）的游戏介绍并玩游戏。然后回答问题"><a href="#阅读“牧师与恶魔过河”（-http-www-17yy-com-f-69854-html）的游戏介绍并玩游戏。然后回答问题" class="headerlink" title="阅读“牧师与恶魔过河”（ http://www.17yy.com/f/69854.html）的游戏介绍并玩游戏。然后回答问题"></a>阅读“牧师与恶魔过河”（ <a target="_blank" rel="noopener" href="http://www.17yy.com/f/69854.html%EF%BC%89%E7%9A%84%E6%B8%B8%E6%88%8F%E4%BB%8B%E7%BB%8D%E5%B9%B6%E7%8E%A9%E6%B8%B8%E6%88%8F%E3%80%82%E7%84%B6%E5%90%8E%E5%9B%9E%E7%AD%94%E9%97%AE%E9%A2%98">http://www.17yy.com/f/69854.html）的游戏介绍并玩游戏。然后回答问题</a></h3><h4 id="游戏涉及哪些类。请列表说明"><a href="#游戏涉及哪些类。请列表说明" class="headerlink" title="游戏涉及哪些类。请列表说明"></a>游戏涉及哪些类。请列表说明</h4><ul>
<li>牧师类</li>
<li>魔鬼类</li>
<li>小船类</li>
<li>岸类</li>
</ul>
<h4 id="游戏中有哪些对象，各几个。例如，船（一个）"><a href="#游戏中有哪些对象，各几个。例如，船（一个）" class="headerlink" title="游戏中有哪些对象，各几个。例如，船（一个）"></a>游戏中有哪些对象，各几个。例如，船（一个）</h4><ul>
<li>船（一个）</li>
<li>魔鬼（三个）</li>
<li>牧师（三个）</li>
<li>场景（一个）</li>
<li>岸（两个）</li>
</ul>
<h4 id="类和对象的区别是什么？举一个例子说明"><a href="#类和对象的区别是什么？举一个例子说明" class="headerlink" title="类和对象的区别是什么？举一个例子说明"></a>类和对象的区别是什么？举一个例子说明</h4><p>类是一种代码模板，它描述了物体的状态和行为并提供了实现；而对象是一个类型创建出来的实例，这个实例拥有类的行为，并且维护了一份自己的状态。</p>
<p>例如通过创建一个船类的实例可以构造出一个船的对象。</p>
<h4 id="游戏中的魔鬼，有哪些属性和方法？"><a href="#游戏中的魔鬼，有哪些属性和方法？" class="headerlink" title="游戏中的魔鬼，有哪些属性和方法？"></a>游戏中的魔鬼，有哪些属性和方法？</h4><p>属性：</p>
<ul>
<li>name: 名称</li>
<li>isOnBoat: 是否在船上</li>
<li>position: 位置</li>
<li>direction: 面向的方向</li>
</ul>
<p>方法：</p>
<ul>
<li>setName: 设置名称</li>
<li>getName: 获取名称</li>
<li>setPosition: 设置位置</li>
<li>getPosition: 获取位置</li>
<li>setIsOnBoat: 设置是否在船上</li>
<li>getIsOnBoat: 获取是否在船上</li>
<li>setDirection: 设置面向的方向</li>
<li>getDirection: 获取面向的方向</li>
<li>killPriest: 杀掉牧师</li>
<li>constructor: 构造函数</li>
<li>finalizer: 析构函数</li>
</ul>
<h4 id="假设魔鬼被鼠标点中，会执行onclick事件，请用文字-（伪代码）描述这个事件中魔鬼与其他对象沟通的过程。"><a href="#假设魔鬼被鼠标点中，会执行onclick事件，请用文字-（伪代码）描述这个事件中魔鬼与其他对象沟通的过程。" class="headerlink" title="假设魔鬼被鼠标点中，会执行onclick事件，请用文字 （伪代码）描述这个事件中魔鬼与其他对象沟通的过程。"></a>假设魔鬼被鼠标点中，会执行onclick事件，请用文字 （伪代码）描述这个事件中魔鬼与其他对象沟通的过程。</h4><p>选中魔鬼后，在 onclick 事件中将会执行以下步骤：</p>
<ol>
<li>获取当前是否在船上</li>
<li>如果不在船上<ol>
<li>获取船的空位数量</li>
<li>如果还有空位<ol>
<li>将魔鬼从岸上移动到船上</li>
<li>将该魔鬼对象加到船上</li>
<li>将该魔鬼对象从岸上删除</li>
</ol>
</li>
<li>如果没有空位<ol>
<li>什么都不做</li>
</ol>
</li>
</ol>
</li>
<li>如果在船上<ol>
<li>将魔鬼从船上移动到岸上</li>
<li>将该魔鬼对象加到岸上</li>
<li>将该魔鬼对象从船上删除</li>
</ol>
</li>
<li>判断游戏的输赢</li>
</ol>
<h4 id="类或对象会是动词吗？"><a href="#类或对象会是动词吗？" class="headerlink" title="类或对象会是动词吗？"></a>类或对象会是动词吗？</h4><p>不会。</p>
<p>类是实体的描述和抽象，是一种包含行为和状态定义的数据类型；而对象是类的实体，属于名词，不是动词。</p>
<p>而动词一般用于形容类的方法或函数。</p>


      

    </section>
    
      <section class='ArticleMeta'>
          <div>
            发布于&nbsp;
            <time datetime="2020-11-07T09:14:50.519Z" itemprop="datePublished">
              2020-11-07
            </time>
          </div>
          
      </section>
    
    
</article>

  
</div>

            <footer>
    <div>© 2021 - Steven He </div>
    <div>
        <span>
            Powered by <a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a>
        </span>
        ,
        <span>
            Theme - <a target="_blank" rel="noopener" href="https://github.com/nameoverflow/hexo-theme-icalm">Icalm</a>
        </span>
    </div>
</footer>

        </div>
    </div>
</div>

<script src="/js/pager/dist/singlepager.js"></script>

<script>
var sp = new Pager('data-pager-shell')

</script>
</body>
</html>